package com.service;

import com.data_object.AlbumDO;
import com.data_object.TrackDO;
import com.repository.AlbumRepo;
import com.repository.RelationRepo;
import com.repository.TrackRepo;
import com.view_object.BindView;
import com.view_object.UserVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yuisama
 * @date 2023/03/11 15:40
 **/
public class AlbumService {
    private final AlbumRepo albumRepo = new AlbumRepo();
    private final RelationRepo relationRepo = new RelationRepo();
    private  final TrackRepo trackRepo = new TrackRepo();

    public Object getBindInfo(UserVO currentUser, int aid) {
        AlbumDO albumDO = albumRepo.selectOneByUidAndAid(currentUser.uid,aid);
        if(albumDO == null){
            throw  new RuntimeException("aid 不存在或者不属于这个用户");
        }

        List<Integer> tidList = relationRepo.selectListByAid(aid);
        List<TrackDO> trackDOList;
        if(tidList.isEmpty()){
            trackDOList = new ArrayList<>();
        }else{
            trackDOList = trackRepo.selectListByTidList(tidList);
        }
        //接下来对三个数据进行组合
        return new BindView(currentUser,albumDO,trackDOList);
    }
}

